<template>
  <!-- 首页轮播图与广告 -- 推荐部分 -->
  <div class="swiper">
    <div class="top">
      <div class="swiper mySwiper-swiper">
        <div class="swiper-wrapper">
          <!-- 等到数据获取到的时候再添加背景 -->
          <div
            class="swiper-slide"
            :style="{
              background: `url(https://gitee.com/mrdai123/pic-go/raw/master/heima_swiper/1.webp)`,
            }"
          >
            <img src="./img/1.jpg" />
          </div>
          <div class="swiper-slide">
            <img src="./img/2.jpg" />
          </div>
          <div class="swiper-slide">
            <img src="./img/3.jpg" />
          </div>
        </div>
        <div class="swiper-pagination"></div>
      </div>
      <div class="ad">
        <a href="javascript:;">
          <img src="@/assets/download.png" alt="下载客户端" />
          <p>PC 安卓 iPhone WP iPad Mac 六大客户端</p>
        </a>
      </div>
      <!-- 移动切换按钮 -->
      <div class="swiper-button-next"></div>
      <div class="swiper-button-prev"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: "swiper",
  mounted() {
    // swiper初始化
    this.swiper();
  },
  methods: {
    swiper() {
      var swiper = new Swiper(".mySwiper-swiper", {
        slidesPerView: 1,
        loop: true,
        autoplay: true,
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
        },
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
// 轮播图与右侧广告
.swiper {
  width: 100%;
  height: 285px;
  background: url("./img/1.jpg");
  position: relative;
  z-index: 3;
  // 模糊背景
  &:after {
    content: "";
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    background: inherit;
    background-size: 10000px;
    background-position: center;
    filter: brightness(70%);
    z-index: 2;
  }
  .top {
    display: flex;
    width: 984px;
    margin: 0 auto;
    // 给Swiper切换按钮留出空间
    padding: 0 75px;
    // Swiper切换按钮
    position: relative;
    z-index: 3;
    .ad {
      width: 254px;
      height: 285px;
      background-color: red;
      overflow: hidden;
      position: relative;
      // z-index: 3;
      img {
        width: 254px;
      }
      p {
        color: #8d8d8d;
        font-size: 12px;
        position: absolute;
        bottom: 20px;
        left: 12px;
      }
    }
  }
}
</style>

<style scoped>
/* 设置宽度 */
.mySwiper-swiper {
  width: 730px;
}
/* 设置模糊 */
.mySwiper-swiper::after {
  position: relative;
  z-index: 99;
}
.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #333;
}
/* 自定义 */
.swiper-button-next,
.swiper-button-prev {
  color: #fff;
  opacity: 0.9;
}
.swiper-button-next::after,
.swiper-button-prev::after {
  font-size: 40px;
}
/* 样式穿透 */
::v-deep .swiper-pagination-bullet {
  width: 6px;
  height: 6px;
  background: #fff;
  opacity: 0.7;
}
::v-deep .swiper-pagination-bullet-active {
  background: #b60b0b;
}
.swiper-slide img {
  width: 100%;
  height: 100%;
}
</style>